package com.ruoyi.house_sale.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.house_sale.domain.*;
import com.ruoyi.house_sale.service.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收款管理Controller
 * 
 * @author ruoyi
 * @date 2022-04-08
 */
@RestController
@RequestMapping("/house_sale/finance")
public class FinanceController extends BaseController
{
    @Autowired
    private IFinanceService financeService;
    @Resource
    private IPaidTypeService paidtypeService;
    @Resource
    private ITicketService ticketService;
    @Resource
    private IPaidSortService paidsortService;
    @Resource
    private IBankService bankService;
    @Resource
    private IBankCompanyService bankcompanyService;
    /**
     * 查询收款管理列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:finance:list')")
    @GetMapping("/list")
    public TableDataInfo list(Finance finance)
    {
        startPage();
        List<Finance> list = financeService.selectFinanceList(finance);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('house_sale:finance:list1')")
    @GetMapping("/list1/{buyid}")
    public TableDataInfo list1(@PathVariable("buyid") Long  buyid)
    {
        startPage();
        List<Finance> list = financeService.selectFinanceByBuyId(buyid);
        return getDataTable(list);

    }

    @GetMapping("/paidtypeList")
    public AjaxResult paidtypeList(){

        List<PaidType> list = paidtypeService.selectPaidTypeList(new PaidType());
        List<Ticket> list1 = ticketService.findAllTicket();
        List<PaidSort> list2 = paidsortService.selectPaidSortList(new PaidSort());
        List<Bank> list3 = bankService.selectBankList(new Bank());
        List<BankCompany> list4 = bankcompanyService.selectBankCompanyList(new BankCompany());
        AjaxResult ajax = AjaxResult.success();
        ajax.put("paidtypeList", list);
        ajax.put("ticketList", list1);
        ajax.put("paidsortList", list2);
        ajax.put("outbankList", list3);
        ajax.put("inbankList", list4);
        return ajax;
    }
    @GetMapping("/selectyfMoney/{buyid}")
    public AjaxResult selectyfMoney(@PathVariable("buyid") Long buyid){

        Float yfmoney = financeService.selcetyfmoney(buyid);
        AjaxResult ajax = AjaxResult.success();
        ajax.put("yfmoney", yfmoney);

        return ajax;
    }
    @PutMapping( "/invalid")
    public AjaxResult invalid(@RequestBody Finance form2)
    {
        return toAjax(financeService.beInvalid(form2));

    }
    /**
     * 导出收款管理列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:finance:export')")
    @Log(title = "收款管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Finance finance)
    {
        List<Finance> list = financeService.selectFinanceList(finance);
        ExcelUtil<Finance> util = new ExcelUtil<Finance>(Finance.class);
        util.exportExcel(response, list, "收款管理数据");
    }

    /**
     * 获取收款管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:finance:query')")
    @GetMapping(value = "/{financeid}")
    public AjaxResult getInfo(@PathVariable("financeid") Long financeid)
    {
        return AjaxResult.success(financeService.selectFinanceByFinanceid(financeid));
    }

    /**
     * 新增收款管理
     */
    @PreAuthorize("@ss.hasPermi('house_sale:finance:add')")
    @Log(title = "收款管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Finance finance)
    {

        return toAjax(financeService.insertFinance(finance));
    }

    /**
     * 修改收款管理
     */
    @PreAuthorize("@ss.hasPermi('house_sale:finance:edit')")
    @Log(title = "收款管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Finance finance)
    {
        return toAjax(financeService.updateFinance(finance));
    }

    /**
     * 删除收款管理
     */
    @PreAuthorize("@ss.hasPermi('house_sale:finance:remove')")
    @Log(title = "收款管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{financeids}")
    public AjaxResult remove(@PathVariable Long[] financeids)
    {
        return toAjax(financeService.deleteFinanceByFinanceids(financeids));
    }
}
